<template>
    <div class="versionManage">
        <el-tabs v-model="activeName" @tab-click="handleClick">
            <el-tab-pane label="用户端" name="1">
            </el-tab-pane>
            <el-tab-pane label="crm端" name="2">
            </el-tab-pane>
        </el-tabs>
        <el-table
            :data="appletCodeManageList"
            border
            tooltip-effect="dark"
            style="width: 100%; height: calc(100vh - 240px)"
            >
            <el-table-column
                prop="versionNum"
                align="center"
                label="版本号"
                width="200">
            </el-table-column>
            <el-table-column
                label="类型"
                align="center"
                width="200">
                <template slot-scope="scope">
                    <div>{{ scope.row.versionType == 1 ? '用户端' : 'crm端' }}</div>
                </template>
            </el-table-column>
            <el-table-column
                prop="templateId"
                align="center"
                label="模板ID"
                width="160">
            </el-table-column>
            <el-table-column
                prop="desc"
                align="center"
                label="描述">
            </el-table-column>
            <el-table-column
                label="创建时间"
                align="center"
                width="200">
                <template slot-scope="scope">
                    <div>{{ scope.row.createTime | formatDateMin }}</div>
                </template>
            </el-table-column>
            <el-table-column
                label="操作"
                align="center"
                width="200">
                <template slot-scope="scope">
                    <el-button class="checkCard" @click="codeCommit(scope.row)" type="text" style="color: #51cdcb;" size="medium">代码提交</el-button>
                </template>
            </el-table-column>
        </el-table>
        <div class="page">
            <el-pagination
            @current-change="handleCurrentChange"
            :current-page.sync="pageNum"
            :page-sizes="[10]"
            :page-size="10"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
            </el-pagination>
        </div>
    </div>
</template>
<script>
import { getCookie } from '@/utils/util.js'
import { serverUrl } from "@/utils/server.js";
const Qs = require('qs');
export default {
    data () {
        return {
            activeName: '1',
            appletCodeManageList: [],
            pageNum: 1,
            total: 0
        }
    },
    created() {
        this.getAppletCodeManageList()
    },
    methods: {
        getAppletCodeManageList() {
            let params = {
                pageNum: this.pageNum,
                versionType: this.activeName
            }
            //  配置请求头
            let headers = new Headers()
            headers.append('token', getCookie('token'))
            headers.append('Content-Type', 'application/x-www-form-urlencoded')
            fetch(serverUrl.baseURL + 'Wechat/appletCodeManageList', {
                headers: headers,
                method: 'POST',
                body: Qs.stringify(params)
            }).then(res => {
                return res.json();
            }).then(res => {
                if (res.code == 200) {
                    this.appletCodeManageList = res.data.pageInfo.list;
                    this.total = res.data.pageInfo.total;
                } else {
                    this.appletCodeManageList = [];
                    this.$message({
                        message: res.message,
                        type: 'warning'
                    });
                }
            }).catch(err => {
                this.appletCodeManageList = [];
            })
        },
        // 页面变更
        handleCurrentChange () {
            this.getAppletCodeManageList();
        },
        codeCommit(item) {
            let params = {
                versionId: item.versionId
            }
            //  配置请求头
            let headers = new Headers()
            headers.append('token', getCookie('token'))
            headers.append('Content-Type', 'application/x-www-form-urlencoded')
            fetch(serverUrl.baseURL + 'Wechat/commit', {
                headers: headers,
                method: 'POST',
                body: Qs.stringify(params)
            }).then(res => {
                return res.json();
            }).then(res => {
                if (res.code === "200") {
                    this.$message({
                        message: "提交成功",
                        type: 'success'
                    });
                } else {
                    this.$message({
                        message: res.errmsg ? res.errmsg : res.message,
                        type: 'warning'
                    });
                }
            }).catch(err => {
            })
        },
        handleClick() {
            this.pageNum = 1
            this.appletCodeManageList = []
            this.getAppletCodeManageList();
        }
    }
}
</script>
<style lang="scss">
.versionManage{
    background: #fff;
    .page{
        padding: 10px 0;
        text-align: center;
    }
}
</style>
